package MtG.client.panels;

import java.awt.Label;
import javax.swing.Box;
import javax.swing.JDialog;
import javax.swing.JFrame;

import MtG.publicClass.Player;

/**
 * MessageDispayer.java is a class for displaying incoming messages from server.
 * @author Marek Sirp
 * @author Jaan Sepp
 */
public class MessageDisplayer extends JDialog{

	/**
	 * Determines if a de-serialized file is compatible with this class.
	 */
	private static final long serialVersionUID = -484027840194318985L;
	/**
	 * Create a box in which components will be displayed in a column.
	 */
	private Box b = Box.createVerticalBox();
	/**
	 * Label for the message that will be displayed.
	 */
	private Label message = new Label();
	/**
	 * constant which determines how long message stay on screen.
	 */
	public final int TIMEALIVE = 1500;
	
	/**
	 * @param player - actor, who did something.
	 * @param string - message.
	 * @param frame - parent frame.
	 */
	public MessageDisplayer(Player player, String string, JFrame frame){
		message.setText(string + player.getName());
        setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
	    getContentPane().add(b);
	    b.add(message);
	    pack();
	    setLocation((frame.getWidth()-this.getWidth())/2, (frame.getHeight()-this.getHeight())/2);
	    setVisible(true);
		try {
			synchronized (this) {
				this.wait(TIMEALIVE);
			}
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		setVisible(false);
	}		
}
